/*
 * Copyright 2011 Raimon Rodriguez
 * 
 * This file is part of sgfx.
 * 
 * sgfx is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * sgfx is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with sgfx. If not, see <http://www.gnu.org/licenses/>.
 */

package com.googlecode.sgfx.base;

import java.awt.Component;
import java.awt.event.KeyEvent;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.LayoutStyle;

/**
 *
 * @author raimon.rodriguez
 */
public class FocusTraversalFrame extends JFrame {

    public FocusTraversalFrame() {
        initComponents();
//        setFocusTraversalPolicy(FocusTraversal.newPolicy(nameTextField, surnameTextField));
    }


    public JButton getCancelButton() {
        return cancelButton;
    }

    public JTextField getCityTextField() {
        return cityTextField;
    }

    public JTextField getCountryTextField() {
        return countryTextField;
    }

    public JTextField getEmailTextField() {
        return emailTextField;
    }

    public JRadioButton getFemaleRadioButton() {
        return femaleRadioButton;
    }

    public JRadioButton getMaleRadioButton() {
        return maleRadioButton;
    }

    public JComboBox getMaritalStatusComboBox() {
        return maritalStatusComboBox;
    }

    public JTextField getNameTextField() {
        return nameTextField;
    }

    public JButton getOkButton() {
        return okButton;
    }

    public JTextField getPostcodeTextField() {
        return postcodeTextField;
    }

    public JTextField getStreetTextField() {
        return streetTextField;
    }

    public JTextField getSurnameTextField() {
        return surnameTextField;
    }

    public void setFormFocusable() {
        nameTextField.setFocusable(true);
        surnameTextField.setFocusable(true);
        emailTextField.setFocusable(true);
        maleRadioButton.setFocusable(true);
        femaleRadioButton.setFocusable(true);
        maritalStatusComboBox.setFocusable(true);
        streetTextField.setFocusable(true);
        postcodeTextField.setFocusable(true);
        cityTextField.setFocusable(true);
        countryTextField.setFocusable(true);
    }

    public static void main(String... pArgs) throws Exception {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                FocusTraversalFrame frame = new FocusTraversalFrame();
//                FocusTraversal.setDefaultForwardTraversalKeys(Keys.stroke(KeyEvent.VK_RIGHT));
                frame.setFormFocusable();
                frame.setVisible(true);
            }
        });
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        nameLabel = new JLabel();
        nameTextField = new JTextField();
        surnameLabel = new JLabel();
        surnameTextField = new JTextField();
        emailLabel = new JLabel();
        emailTextField = new JTextField();
        genderLabel = new JLabel();
        maleRadioButton = new JRadioButton();
        femaleRadioButton = new JRadioButton();
        maritalStatusLabel = new JLabel();
        maritalStatusComboBox = new JComboBox();
        basicAddressPanel = new JPanel();
        streetLabel = new JLabel();
        streetTextField = new JTextField();
        cityLabel = new JLabel();
        cityTextField = new JTextField();
        countryLabel = new JLabel();
        countryTextField = new JTextField();
        postcodeLabel = new JLabel();
        postcodeTextField = new JTextField();
        cancelButton = new JButton();
        okButton = new JButton();

        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        nameLabel.setText("Name:");

        nameTextField.setFocusable(false);
        nameTextField.setName("nameTextField"); // NOI18N

        surnameLabel.setText("Surname:");

        surnameTextField.setFocusable(false);
        surnameTextField.setName("surnameTextField"); // NOI18N

        emailLabel.setText("Email:");

        emailTextField.setFocusable(false);
        emailTextField.setName("emailTextField"); // NOI18N

        genderLabel.setText("Gender:");

        maleRadioButton.setText("Male");
        maleRadioButton.setFocusable(false);
        maleRadioButton.setName("maleRadioButton"); // NOI18N

        femaleRadioButton.setText("Female");
        femaleRadioButton.setFocusable(false);
        femaleRadioButton.setName("femaleRadioButton"); // NOI18N

        maritalStatusLabel.setText("Marital status:");

        maritalStatusComboBox.setModel(new DefaultComboBoxModel(new String[] { "Single", "Divorced", "Married" }));
        maritalStatusComboBox.setFocusable(false);
        maritalStatusComboBox.setName("maritalStatusComboBox"); // NOI18N

        streetLabel.setText("Street:");

        streetTextField.setFocusable(false);
        streetTextField.setName("streetTextField"); // NOI18N

        cityLabel.setText("City:");

        cityTextField.setFocusable(false);
        cityTextField.setName("cityTextField"); // NOI18N

        countryLabel.setText("Country:");

        countryTextField.setFocusable(false);
        countryTextField.setName("countryTextField"); // NOI18N

        GroupLayout basicAddressPanelLayout = new GroupLayout(basicAddressPanel);
        basicAddressPanel.setLayout(basicAddressPanelLayout);
        basicAddressPanelLayout.setHorizontalGroup(
            basicAddressPanelLayout.createParallelGroup(GroupLayout.LEADING)
            .add(basicAddressPanelLayout.createSequentialGroup()
                .add(basicAddressPanelLayout.createParallelGroup(GroupLayout.LEADING)
                    .add(streetLabel)
                    .add(cityLabel)
                    .add(countryLabel))
                .addPreferredGap(LayoutStyle.RELATED)
                .add(basicAddressPanelLayout.createParallelGroup(GroupLayout.LEADING)
                    .add(streetTextField, GroupLayout.PREFERRED_SIZE, 182, GroupLayout.PREFERRED_SIZE)
                    .add(cityTextField, GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)
                    .add(countryTextField, GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)))
        );

        basicAddressPanelLayout.linkSize(new Component[] {cityTextField, countryTextField, streetTextField}, GroupLayout.HORIZONTAL);

        basicAddressPanelLayout.setVerticalGroup(
            basicAddressPanelLayout.createParallelGroup(GroupLayout.LEADING)
            .add(basicAddressPanelLayout.createSequentialGroup()
                .add(basicAddressPanelLayout.createParallelGroup(GroupLayout.BASELINE)
                    .add(streetTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .add(streetLabel))
                .addPreferredGap(LayoutStyle.RELATED)
                .add(basicAddressPanelLayout.createParallelGroup(GroupLayout.BASELINE)
                    .add(cityTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .add(cityLabel))
                .addPreferredGap(LayoutStyle.RELATED)
                .add(basicAddressPanelLayout.createParallelGroup(GroupLayout.BASELINE)
                    .add(countryTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .add(countryLabel)))
        );

        postcodeLabel.setText("Postcode:");

        postcodeTextField.setFocusable(false);
        postcodeTextField.setName("postcodeTextField"); // NOI18N

        cancelButton.setText("Cancel");
        cancelButton.setFocusable(false);
        cancelButton.setName("cancelButton"); // NOI18N

        okButton.setText("Ok");
        okButton.setFocusable(false);
        okButton.setName("okButton"); // NOI18N

        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(GroupLayout.LEADING)
                            .add(nameLabel)
                            .add(surnameLabel)
                            .add(emailLabel))
                        .addPreferredGap(LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(GroupLayout.LEADING)
                            .add(nameTextField, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)
                            .add(surnameTextField, GroupLayout.PREFERRED_SIZE, 167, GroupLayout.PREFERRED_SIZE)
                            .add(emailTextField, GroupLayout.PREFERRED_SIZE, 167, GroupLayout.PREFERRED_SIZE))
                        .add(18, 18, 18)
                        .add(layout.createParallelGroup(GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(21, 21, 21)
                                .add(maleRadioButton)
                                .addPreferredGap(LayoutStyle.RELATED)
                                .add(femaleRadioButton))
                            .add(genderLabel)
                            .add(layout.createSequentialGroup()
                                .add(maritalStatusLabel)
                                .addPreferredGap(LayoutStyle.RELATED)
                                .add(maritalStatusComboBox, 0, 140, Short.MAX_VALUE)))
                        .addContainerGap())
                    .add(GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(okButton)
                        .addPreferredGap(LayoutStyle.UNRELATED)
                        .add(cancelButton)
                        .add(17, 17, 17))
                    .add(layout.createSequentialGroup()
                        .add(basicAddressPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(postcodeLabel)
                        .addPreferredGap(LayoutStyle.RELATED)
                        .add(postcodeTextField, GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(GroupLayout.BASELINE)
                            .add(nameTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .add(nameLabel))
                        .addPreferredGap(LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(GroupLayout.BASELINE)
                            .add(surnameTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .add(surnameLabel))
                        .addPreferredGap(LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(GroupLayout.BASELINE)
                            .add(emailTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .add(emailLabel)))
                    .add(layout.createSequentialGroup()
                        .add(genderLabel)
                        .addPreferredGap(LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(GroupLayout.BASELINE)
                            .add(maleRadioButton)
                            .add(femaleRadioButton))
                        .add(9, 9, 9)
                        .add(layout.createParallelGroup(GroupLayout.BASELINE)
                            .add(maritalStatusLabel)
                            .add(maritalStatusComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(basicAddressPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .add(37, 37, 37)
                        .add(layout.createParallelGroup(GroupLayout.BASELINE)
                            .add(cancelButton)
                            .add(okButton)))
                    .add(layout.createParallelGroup(GroupLayout.BASELINE)
                        .add(postcodeLabel)
                        .add(postcodeTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private JPanel basicAddressPanel;
    private JButton cancelButton;
    private JLabel cityLabel;
    private JTextField cityTextField;
    private JLabel countryLabel;
    private JTextField countryTextField;
    private JLabel emailLabel;
    private JTextField emailTextField;
    private JRadioButton femaleRadioButton;
    private JLabel genderLabel;
    private JRadioButton maleRadioButton;
    private JComboBox maritalStatusComboBox;
    private JLabel maritalStatusLabel;
    private JLabel nameLabel;
    private JTextField nameTextField;
    private JButton okButton;
    private JLabel postcodeLabel;
    private JTextField postcodeTextField;
    private JLabel streetLabel;
    private JTextField streetTextField;
    private JLabel surnameLabel;
    private JTextField surnameTextField;
    // End of variables declaration//GEN-END:variables
}
